import QtQuick 2.3
import QtMultimedia 5.4
import QtQuick.Layouts 1.1
FView {
    id: camcontainer
    color: "ghostwhite"

    property string fileUrl: "" // don't set url type.
    property var model: null
    property int index: 0
    property var picture: null
    signal imageCaptured(string file)

    Item {
        width: camcontainer.width
        height: camcontainer.height
        Camera {
            id: camera

            captureMode: Camera.CaptureStillImage

            imageCapture {
                onImageCaptured: {
                    photoPreview.source = preview  // Show the preview in an Image
                }
                onImageSaved: {
                    camcontainer.imageCaptured(Path.toUrl(path));
                }
            }
        }

        ColumnLayout {
            anchors.fill: parent
            anchors.margins: 9 * __factor__
            VideoOutput {
                source: camera
                Layout.fillHeight: true
                Layout.fillWidth: true
                focus : visible // to receive focus and capture key events when visible
                visible: !btnCapture.mode
                autoOrientation: true
            }

            Image {
                id: photoPreview
                Layout.fillHeight: true
                Layout.fillWidth: true
                visible: btnCapture.mode
            }


            FButton {
                id: btnCapture
                text:  !mode ? "拍照" : "重拍"
                Layout.preferredHeight: 42 * __factor__
                Layout.preferredWidth:  parent.width / 2
                Layout.alignment: Qt.AlignHCenter
                property bool mode: false
                onClicked: {
                    camera.imageCapture.capture();
                    mode = !mode;
                }
            }


        }
    }
}
